package com.xatu.yl.storeshopping.util;

import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.namespace.R;

public class ToastUtil extends AppCompatActivity {
    private Context context;
    public ToastUtil(Context context){
        this.context = context;
    }
    public void showToast(String alertContext,int alertIcon,int textColor,int duration){
        View layout = View.inflate(context, R.layout.toast_shape, null);

//        LayoutInflater inflater = new View(context).getLayoutInflater();
//        View layout = inflater.inflate(R.layout.toast_shape, null);

        TextView text = layout.findViewById(R.id.text);
        ImageView toast_icon = layout.findViewById(R.id.toast_icon);
        text.setText(alertContext);
        text.setTextColor(context.getResources().getColor(textColor));
        toast_icon.setImageResource(alertIcon);

        Toast toast = new Toast(context);
        //toast.setGravity(Gravity.CENTER_HORIZONTAL, 0, 60);
        toast.setDuration(duration);
        toast.setView(layout);
        toast.show();
    }
}
